new Thread(new Runnable() {
            @Override
            public void run() {
                HttpURLConnection connection=null;
                BufferedReader reader=null;
                try{
                    URL url=new URL("http://www.baidu.cn");
                    connection=(HttpURLConnection)url.openConnection();
                    connection.setRequestMethod("GET");
                    connection.setConnectTimeout(8000);
                    connection.setReadTimeout(8000);
                    InputStream in = connection.getInputStream();
                    reader =new BufferedReader(new InputStreamReader(in));
                    StringBuilder response = new StringBuilder();
                    String line;
                    while((line = reader.readLine())!=null){

                        response.append(line);
                    }
                        showResponse(response.toString());

                }catch(Exception e){
                    e.printStackTrace();

                }finally{

                    if(reader != null){
                        try{
                            reader.close();//������Ǿֲ���Ҫ����

                        }catch(IOException e){
                            e.printStackTrace();
                        }
                    }

                    if(connection != null){

                        connection.disconnect();
                    }
                }
            }
        }){


        }.start();


//// ��װ����
package com.example.administrator.nima;

import java.io.BufferedReader;
import java.io.Externalizable;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * Created by Administrator on 2017/6/21.
 */

public class HttpUtil {

    public static String sendHttpRequest(String address){

        HttpURLConnection connection=null;
        try{
            URL url=new URL(address);
            connection=(HttpURLConnection)url.openConnection();
            connection.setRequestMethod("GET");
            connection.setConnectTimeout(8000);
            connection.setReadTimeout(8000);
            connection.setDoInput(true);
            connection.setDoOutput(true);
            InputStream in=connection.getInputStream();
            BufferedReader reader = new BufferedReader(new InputStreamReader(in));
            StringBuilder response=new StringBuilder();
            String line;
            while((line = reader.readLine())!=null){

                response.append(line);
            }

            return response.toString();

        }catch(Exception e){

            e.printStackTrace();
            return e.getMessage();
        }finally {
            if(connection != null){

                connection.disconnect();
            }


        }


    }

}
